﻿using AspDotNet.Framework.Mvc.FirstDemo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AspDotNet.Framework.Mvc.FirstDemo.Controllers
{
    public class ValidationController : Controller
    {
        // GET: Validation
        public ActionResult Index()
        {
            return View(Person.People);
        }

        public ActionResult Edit(int id)
        {
            var temp = Person.People.Find(p => p.id == id);
            return View(temp);
        }

        [HttpPost]
        public ActionResult Edit(Person person)
        {
            if (ModelState.IsValid)
            {
                var temp = Person.People.Find(p => p.id == person.id);

                Person.People.Remove(temp);
                Person.People.Add(person);
                return RedirectToAction("Index");
            }
            return View(person);
        }

    }
}